import javax.management.*;
import java.lang.management.ManagementFactory;

/**
 * Created by H-209-FX-XY on 2018/3/22.
 */
public class HelloAgent {
    public static void main(String[] args) throws MalformedObjectNameException, NotCompliantMBeanException, InstanceAlreadyExistsException, MBeanRegistrationException, InterruptedException {
        /**通过工厂类获取MBeanServer,用来做MBean容器*/
        MBeanServer server = ManagementFactory.getPlatformMBeanServer();
        /**取名规范 : '域名:name=MBean名称' 其中域名和MBean可以任意取,用来标识定义的这个MBean的实现类*/
        ObjectName objectName = new ObjectName("jmxBean:name=hello");
        server.registerMBean(new Hello(),objectName);
        Thread.sleep(60*60*1000);
    }
}
